package demo.practice.bit;

public class P338 {


    public int[] countBits(int num) {

        int[] res= new int[num];

        for(int i=0;i<=num;i++){
            res[i]=   getBitCount(i);
        }

        return res;
    }

    private int getBitCount(int i){

        int count=0;
        while (i>0){
            count+= (i&1);
            i>>=1;
        }
        return count;
    }
}
